#飞船类
#要和飞船图片相关关联
#操作飞船类的对象就等于操作飞船图片
import pygame.image
from  pygame.sprite import Sprite
class Ship(Sprite):
    def __init__(self,ai_settings,screen):
        super().__init__()
        self.screen = screen
        self.ai_settings = ai_settings
        #关联图像
        self.image = pygame.image.load("images/ship.bmp")
        #图片的宽高
        self.rect = self.image.get_rect()
        #print("图片矩形",self.rect)
        #屏幕的宽高
        self.screen_rect =  self.screen.get_rect()
        #print("屏幕矩形",self.screen_rect)
        #设置飞船图片的位置
        #设置水平位置
        self.rect.centerx = self.screen_rect.centerx
        self.rect.bottom = self.screen_rect.bottom
        #print("图片矩形",self.rect)
        #移动标准为，可以往右移
        self.moving_right = False
        self.moving_left = False

    def update(self):
        #如果不越界
        if self.moving_right == True and  self.rect.right < self.screen_rect.right :
            self.rect.centerx = self.rect.centerx + self.ai_settings.ship_speed_factor
        if self.moving_left == True and self.rect.left >0:
            self.rect.centerx = self.rect.centerx - self.ai_settings.ship_speed_factor
    #绘制图片到窗口
    def blitme(self):
        self.screen.blit(self.image,self.rect)
    def center_ship(self):
        self.center = self.screen_rect.centerx
#get_rect ?   blit ?

